package x;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;


/**
 * The map holds the data about game area. In this case its responsible
 * for both rendering the map and check collision against the grid cells
 * within.
 *
 * Our map is a simple WIDTHxHEIGHT grid containing value 0 to indicate
 * a clear cell and 1 to indicate a wall.
 *
 * @author Daniel Wheeler
 */
public class Map2 extends Map {
    //the ground for the map
        private Image floor;
        /** The value indicating a clear cell */
        private static final int CLEAR = 0;
        /** The value indicating a blocked cell */
        private static final int BLOCKED = 1;
        //cell for building door
        private static final int MINIGAME = 69; // in use for the mini game and testing it in the enviroment

        /** The width in grid cells of our map */
        private static final int WIDTH = 64;
        /** The height in grid cells of our map */
        private static final int HEIGHT = 48;

        /** The rendered size of the tile (in pixels) */
        public static final int TILE_SIZE = 10;

        /** The actual data for our map */
        private int[][] data = new int[WIDTH][HEIGHT];

        private static final int EXIT= 12;
        /**
         * Create a new map with some default contents
         */
        public Map2() {


/*----------------------------------------------level design----------------------*/

            //this makes vertical blocks and horizontal.......may change!
                for (int y=0;y<HEIGHT;y++)
                {
                        data[0][y] = BLOCKED;
                        data[WIDTH - 1][y] = BLOCKED;
                       for (int x=0;x<WIDTH;x++)
                   {

                     data[x][0] = BLOCKED;

                     data[x][HEIGHT - 1] = BLOCKED;

                     }
                }

               data[30][47] = EXIT;
               data[31][47] = EXIT;
               data[32][47] = EXIT;
               data[33][47] = EXIT;
               data[34][47] = EXIT;

                              //Mini game
               data[40][34]=MINIGAME;
               data[41][34]=MINIGAME;
               data[42][34]=MINIGAME;
               data[40][35]=MINIGAME;
               data[41][35]=MINIGAME;
               data[42][35]=MINIGAME;
               data[40][36]=MINIGAME;
               data[41][36]=MINIGAME;
               data[42][36]=MINIGAME;




        }

        /*---------------------------------------------------------------------------------*/
        /**
         * Render the map to the graphics context provided. The rendering
         * is just simple fill rectangles
         *
         */



        public boolean buildingcomplete(float x, float y)
        {
             if (data[(int) x][(int) y] == buildingcomplete)
                return data[(int) x][(int) y] == buildingcomplete;


                else return false; //this should NEVER have to be called


        }




        public void paint(Graphics2D g) {
                // loop through all the tiles in the map rendering them
                // based on whether they block or not
                for (int x=0;x<WIDTH;x++) {
                        for (int y=0;y<HEIGHT;y++) {

                                // so if the cell is blocks, draw a light grey block
                                // otherwise use a dark gray
                                g.setColor(Color.blue);
                                if (data[x][y] == BLOCKED) {
                                        g.setColor(Color.black);
                                }
                                if(data[x][y] == buildingcomplete)
                                       g.setColor(Color.black);

                                if(data[x][y] == MINIGAME) //just added using as a test for the mini game
                                       g.setColor(Color.green);

                                if(data[x][y] == EXIT)
                                       g.setColor(Color.white);
                                // draw the rectangle with a dark outline
                                g.fillRect(x*TILE_SIZE,y*TILE_SIZE,TILE_SIZE,TILE_SIZE);
                                //g.setColor(g.getColor().darker());
                                g.drawRect(x*TILE_SIZE,y*TILE_SIZE,TILE_SIZE,TILE_SIZE);
                        }
                }





        }

        /**
         * Check if a particular location on the map is blocked. Note
         * that the x and y parameters are floating point numbers meaning
         * that we can be checking partially across a grid cell.
         *
         * @param x The x position to check for blocking
         * @param y The y position to check for blocking
         * @return True if the location is blocked
         */
        public boolean blocked(float x, float y)
        {
                // look up the right cell (based on simply rounding the floating
                // values) and check the value
                if (data[(int) x][(int) y] == BLOCKED)
                return data[(int) x][(int) y] == BLOCKED;

                else return false; //this should NEVER have to be called

        }



        //function place the buildings that you can go inside of buildings
        //returns the # of the building


 
public int buildingChecker(float x, float y){

//convert the float numbers to ints
int x2 = (int) x;
int y2 = (int) y;

        location = -1;

            if ((x2 == 30 || x2 == 31 || x2 == 32 || x2 == 33 || x2 == 34)&& y2 == 47)
             location = 12; //lexit for mini game platform

            if ((x2 == 40 || x2 == 41 || x2 == 42) && y2 == 34)
             location = 69;

            if ((x2 == 40 || x2 == 41 || x2 == 42) && y2 == 35)
             location = 69;

            if ((x2 == 40 || x2 == 41 || x2 == 42) && y2 == 36)
             location = 69;

        //if (data[(int) x][(int) y] == BLOCKED)

        //if (data[(int) x][(int) y] == BLOCKED)
            return location;

 }




}

